package com.lst.projectlib.component.CustomView;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lst.projectlib.R;
import com.lst.projectlib.util.ImageLoaderUtil;
import com.lst.projectlib.util.StringUtil;

public class IconTextArrowLayout extends RelativeLayout {
	
	private LayoutInflater inflater = null;
	
	private ImageView leftImg = null;
	private TextView rightImg = null;
	private TextView title = null;
	private TextView subTitle = null;

	public IconTextArrowLayout(Context context,AttributeSet attrs) {
		super(context,attrs);
		inflater=LayoutInflater.from(context);
		inflater.inflate(R.layout.custom_icon_text_arrow, this);
		
		leftImg = (ImageView) findViewById(R.id.custom_more_item_left_img);
		rightImg = (TextView) findViewById(R.id.custom_more_item_right_img);
//		rightImg.setImageResource(R.drawable.img_arrow);
		
		title = (TextView) findViewById(R.id.custom_more_item_title);
		subTitle = (TextView) findViewById(R.id.custom_more_item_subtitle);
	}
	
	/**
	 * 设置自定义布局的内容
	 * @param imageID		左侧图标URL
	 * @param titleText		标题
	 * @param subTitleText	子标题（默认隐藏）
	 */
	public void setContent(int imageID, String titleText, String subTitleText, boolean isShowArrow) {
		leftImg.setImageResource(imageID);
		title.setText(titleText);
		if (!StringUtil.isStringEmpty(subTitleText)) {
			subTitle.setVisibility(View.VISIBLE);
			subTitle.setText(subTitleText);
		} else {
			subTitle.setVisibility(View.GONE);
		}
		
		if (isShowArrow) {
			Drawable drawable = getResources().getDrawable(R.drawable.img_arrow);
			if (drawable != null) {
				drawable.setBounds(0, 0, drawable.getMinimumWidth(),
						drawable.getMinimumHeight());
				rightImg.setCompoundDrawables(null, null, drawable, null);
			}
		} else {
			rightImg.setCompoundDrawables(null, null, null, null);
		}
		
	}
	
	public void setTitleText(String titleText) {
		if (title != null) {
			title.setText(titleText);
		}
	}

	public void setRightText(String text) {
		rightImg.setText(text);
	}
	
	public void setTextColor(int titleColor, int subTitleColor) {
		if (title != null) {
			title.setTextColor(titleColor);
		}
		if (subTitle != null) {
			subTitle.setTextColor(subTitleColor);
		}
	}
	
	public void setTextSize(int titleSize, int subTitleSize, int rightSize) {
		if (title != null) {
			title.setTextSize(titleSize);
		}
		if (subTitle != null) {
			subTitle.setTextSize(subTitleSize);
		}
		if (rightImg != null) {
			rightImg.setTextSize(rightSize);
		}
	}
	
	public void setArrowIcon(int resId, int width, int height) {
		if (rightImg != null) {
			Drawable drawable = getResources().getDrawable(resId);
			if (drawable != null) {
				drawable.setBounds(0, 0, width,	height);
				rightImg.setCompoundDrawables(null, null, drawable, null);
			}
		}
	}
	
	public void setLeftImg(int resId, int width, int height) {
		if (leftImg != null) {
			leftImg.setImageResource(resId);
			leftImg.getLayoutParams().width = width;
			leftImg.getLayoutParams().height = height;
		}
	}
	
	public void setLeftImg(String imgUrl, int defaultResId, int width, int height) {
		if (leftImg != null) {
			ImageLoaderUtil.getInstance().displayImage(imgUrl,leftImg,true,width,height,defaultResId,null);
		}
	}
}
